home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wzun11sr.zip / CHDIR.C < prev    next >
C/C++ Source or Header  |  1992-01-15  |  5KB  |  129 lines

  1. #include <windows.h>
  2. #include <assert.h>
  3. #include <string.h>
  4. #include <io.h>
  5. #include <stdio.h>
  6. #include "wizunzip.h"
  7. #include "chdir.h"
  8. #include "helpids.h"
  9.  
  10.  
  11. #define FILES        39
  12. #define PATH         -16368
  13.  
  14. #define FILESPEC_LEN 12
  15.  
  16. extern char szHelpFileName[];        /* help file name                        */
  17.  
  18. BOOL FAR PASCAL ChDirProc(HWND hDlg, WORD message, WORD wParam, LONG lParam);
  19.  
  20.  
  21. extern char szAppName[];        /* application name                */
  22. static char szFileSpec[FILESPEC_LEN];         // Initial File Specification
  23.  
  24. BOOL FAR PASCAL ChDirProc  (HWND hDlg, WORD message, WORD wParam, LONG lParam)
  25.     {
  26.     char
  27.         cLastChar = 0x00;           /* chr 0 (last char of string)        */
  28.     short       nEditLen = 0x00;    /* Length of Edit Field                */
  29.     int nLBCurSel;                    /* return value from LB_GETCURSEL    */
  30.     int nRetVal;                    /* DlgDirList() return value        */
  31.  
  32.     switch (message)
  33.         {
  34.         case WM_INITDIALOG:
  35.             /* Build destination combo box with appropriate entries.
  36.               * and flag the current choice.
  37.               */
  38.             strcpy(szFileSpec,"*.*");    /* initialize file spec.    */
  39.             SendDlgItemMessage (hDlg, CHDIR_IFNAME, EM_LIMITTEXT, MAX_DIRNAME_LEN, 0L);
  40.             DlgDirList (hDlg, szFileSpec, CHDIR_DLIST, CHDIR_FPATH, PATH);
  41.             SetDlgItemText (hDlg, CHDIR_IFNAME, ".");
  42.             /* save original directory in case user cancels            */
  43.             GetDlgItemText (hDlg, CHDIR_FPATH, szOrigDirName, 
  44.                                         MAX_DIRNAME_LEN);
  45.             InvalidateRect (hDlg, NULL, TRUE);
  46.             return TRUE;
  47.  
  48.         case WM_COMMAND:
  49.             switch (wParam)
  50.                 {
  51.                 case CHDIR_DLIST:
  52.                     switch (HIWORD (lParam))
  53.                         {
  54.                         case LBN_SELCHANGE:
  55.                             DlgDirSelect (hDlg, szDirName, CHDIR_DLIST);
  56.                             SetDlgItemText (hDlg, CHDIR_IFNAME, szDirName);
  57.                             return TRUE;
  58.  
  59.                         case LBN_DBLCLK:
  60.                             DlgDirSelect (hDlg, szDirName, CHDIR_DLIST);
  61.                             DlgDirList (hDlg, szFileSpec, CHDIR_DLIST, CHDIR_FPATH, PATH);
  62.                             assert(strlen(szFileSpec) < FILESPEC_LEN);
  63.                             SetDlgItemText (hDlg, CHDIR_IFNAME, szDirName);
  64.                             SendMessage (hDlg, WM_COMMAND, CHDIR_OK, 0L);
  65.                             return TRUE;
  66.                         }
  67.                     break;
  68.  
  69.                 case CHDIR_OK:
  70.                     GetDlgItemText (hDlg, CHDIR_IFNAME, szDirName, 
  71.                                     MAX_DIRNAME_LEN);
  72.                     nEditLen = lstrlen (szDirName);
  73.                     cLastChar = *AnsiPrev (szDirName, szDirName + nEditLen);
  74.                     if (strchr (szDirName, '*') || strchr (szDirName, '?'))
  75.                         {
  76.                         if (DlgDirList (hDlg, szDirName, CHDIR_DLIST, CHDIR_FPATH, PATH))
  77.                             {
  78.                             lstrcpy (szFileSpec, szDirName);
  79.                             assert(strlen(szFileSpec) < FILESPEC_LEN);
  80.                             SetDlgItemText (hDlg, CHDIR_IFNAME, szFileSpec);
  81.                             }
  82.                         else
  83.                             MessageBeep (0);
  84.                         return TRUE;
  85.                         }
  86.                     /* was anything selected in listbox ?
  87.                      */
  88.                     nLBCurSel = (int)SendMessage(GetDlgItem(hDlg,CHDIR_DLIST), 
  89.                                                     LB_GETCURSEL, 0, 0L);
  90.                     /* If change directory failed or if a directory had
  91.                      * been selected.
  92.                      */
  93.                     if (!(nRetVal = DlgDirList (hDlg, szDirName, CHDIR_DLIST, CHDIR_FPATH, PATH)) ||
  94.                         nLBCurSel != LB_ERR)
  95.                         {
  96.                         strcpy(szDirName, ".");    /* initialize current dir. */
  97.                         lstrcpy (szFileSpec, szDirName);
  98.                         assert(strlen(szFileSpec) < FILESPEC_LEN);
  99.                         SetDlgItemText (hDlg, CHDIR_IFNAME, szFileSpec);
  100.                         if (!nRetVal)    /* if user specified invalid dir.    */
  101.                             MessageBeep (0); /* give stiff reprimand */
  102.  
  103.                         return TRUE;
  104.                         }
  105.                     szDirName [nEditLen] = '\0';
  106.                     GetDlgItemText (hDlg, CHDIR_FPATH, szOrigDirName, 
  107.                                         MAX_DIRNAME_LEN);
  108.                     DoCaption(hMainWnd, szFileName);    /* put name in title bar    */
  109.                     EndDialog (hDlg, TRUE);
  110.                     return TRUE;
  111.  
  112.                 case IDCANCEL:        /* ESC key                        */
  113.                 case CHDIR_CAN:
  114.                     szDirName[0] = 0x00;
  115.                     /* save original directory since DlgDirList touches its arg 2 */
  116.                        SetDlgItemText (hDlg, CHDIR_FPATH, szOrigDirName);
  117.                     DlgDirList(hDlg, szOrigDirName, 0, 0, 0);    /* restore orig. dir.    */
  118.                     GetDlgItemText (hDlg, CHDIR_FPATH, szOrigDirName, MAX_DIRNAME_LEN);
  119.                     EndDialog (hDlg, FALSE);
  120.                     return TRUE;
  121.          case CHDIR_HELP:
  122.                        WinHelp(hDlg,szHelpFileName,HELP_CONTEXT, (DWORD)(HELPID_CHDIR));
  123.                     return TRUE;
  124.                }
  125.         }
  126.     return FALSE;
  127.     }
  128.  
  129.